{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['花', '花开', '花']\n",
      "['花', '花开', '花']\n",
      "['花开']\n",
      "['年', '年', '年', '年', '年', '年']\n",
      "['年年', '年年']\n",
      "['年年', '年年']\n",
      "['年', '年', '年年', '年年']\n",
      "['年花落颜色改，明年花开复谁在？年年岁岁花相似，岁岁年年人不同。']\n",
      "['年花', '年花', '年年岁', '年年人']\n",
      "['年花落颜色改，明年花开复谁在？年年岁岁花']\n",
      "['年花', '年花']\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "test=\"今年花落颜色改，明年花开复谁在？年年岁岁花相似，岁岁年年人不同。\"\n",
    "print(re.findall('花开?',test))\n",
    "print(re.findall('花开*',test))\n",
    "print(re.findall('花开+',test))\n",
    "print(re.findall('年{1}',test))\n",
    "print(re.findall('年{2}',test))\n",
    "print(re.findall('年{2,}',test))\n",
    "print(re.findall('年{1,2}',test))\n",
    "print(re.findall('年.+',test))\n",
    "print(re.findall('年+.',test))\n",
    "print(re.findall('年.+花',test))\n",
    "print(re.findall('年.?花',test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我的个人网页的网址是：http://jiy##ui##able,邮箱是：f_####@qq.com。\n",
      "#####################34##90###########9034########\n",
      "我的个人网页的网址是：http://jiy34ui90able,邮箱是：f_9034@qq.com。\n",
      "##################################################\n",
      "##########：####://#############,###：######@##.###。\n",
      "我的个人网页的网址是#http###jiy34ui90able#邮箱是#f_9034#qq#com#\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "text='我的个人网页的网址是：http://jiy34ui90able,邮箱是：f_9034@qq.com。'\n",
    "print(re.sub('\\d','#',text))\n",
    "print(re.sub('\\D','#',text))\n",
    "print(re.sub('\\s','#',text))\n",
    "print(re.sub('\\S','#',text))\n",
    "print(re.sub('\\w','#',text))\n",
    "print(re.sub('\\W','#',text))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "语料库文件列表:\n",
      " ['书剑恩仇录.txt', '侠客行.txt', '倚天屠龙记.txt', '天龙八部.txt', '射雕英雄传.txt', '白马啸西风.txt', '碧血剑.txt', '神雕侠侣.txt', '笑傲江湖.txt', '越女剑.txt', '连城诀.txt', '雪山飞狐.txt', '飞狐外传.txt', '鸳鸯刀.txt', '鹿鼎记.txt']\n"
     ]
    }
   ],
   "source": [
    "import nltk,re\n",
    "from nltk.corpus import PlaintextCorpusReader\n",
    "corpus_root ='data'\n",
    "filelist = PlaintextCorpusReader (corpus_root,'.*')\n",
    "print('语料库文件列表:\\n',filelist.fileids () )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
